//
//  RWCategoryListViewController.m
//  RedWine
//
//  Created by Liufangfang on 2016/12/29.
//  Copyright © 2016年 HuiBangKe. All rights reserved.
//

#import "RWCategoryListViewController.h"
#import "DOPDropDownMenu.h"

#define kMenuHeight 50.*FTY_HEIGHT_BASE

@interface RWCategoryListViewController ()<DOPDropDownMenuDataSource, DOPDropDownMenuDelegate>

@end

@implementation RWCategoryListViewController

#pragma mark - View LifeCycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavigation];
    [self setCategoryListUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Load Datas

#pragma mark - Config UI

- (void)setNavigation{
    
    self.title = @"分类列表";
}

- (void)setCategoryListUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    DOPDropDownMenu *menu = [[DOPDropDownMenu alloc] initWithOrigin:CGPointMake(0, 0) andHeight:kMenuHeight];
    [self.view addSubview:menu];
    menu.dataSource = self;
    menu.delegate = self;
    menu.indicatorColor = [UIColor cyanColor];
    menu.textSelectedColor = [UIColor redColor];
    
    _categoryListTV = [[UITableView alloc] initWithFrame:CGRectMake(0, kMenuHeight, FTY_SCREEN_WIDTH, FTY_SCREEN_HEIGHT - kMenuHeight) style:UITableViewStylePlain];
    [self.view addSubview:_categoryListTV];
    _categoryListTV.delegate = self;
    _categoryListTV.dataSource = self;
}

#pragma mark - Config Invoke Methods

#pragma mark - Notificaiton Method

#pragma mark - Notificaiton Invoke Methods

#pragma mark - <DOPDropDownMenuDataSource>

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column
{
    if (0 == column) {
        return 0;
    } else if (1 == column){
        return 3;
    } else {
        return 4;
    }
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    
    NSArray *array1 = @[@"默认"];
    NSArray *array2 = @[@"关注度", @"关注度二", @"关注度三"];
    NSArray *array3 = @[@"价格", @"价格一", @"价格二", @"价格三"];
    
    if (indexPath.column == 0) {
        
        return [NSString stringWithFormat:@"%@", array1[indexPath.row]];
    } else if (indexPath.column == 1) {
        return array2[indexPath.row];
    } else {
        return array3[indexPath.row];
    }
    return nil;
}

- (NSInteger)numberOfColumnsInMenu:(DOPDropDownMenu *)menu {
    return 3;
}

//- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForRowAtIndexPath:(DOPIndexPath *)indexPath {
//    return [NSString stringWithFormat:@"第%ld行", indexPath.row];
//
//}

- (NSString *)menu:(DOPDropDownMenu *)menu detailTextForRowAtIndexPath:(DOPIndexPath *)indexPath {
    return @"shane";
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfItemsInRow:(NSInteger)row column:(NSInteger)column{
    if (column == 2) {
        return 3;
    }
    return 0;
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 2) {
        
        if (indexPath.row == 0) {
            return [NSString stringWithFormat:@"莹莹%ld", indexPath.item];
        }
    }
    return nil;
}

//- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
//{
//    return @"yy";
//}

//- (NSString *)menu:(DOPDropDownMenu *)menu detailTextForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
//{
//    return @"emily";
//}

- (void)menu:(DOPDropDownMenu *)menu didSelectRowAtIndexPath:(DOPIndexPath *)indexPath {
    NSLog(@"%ld, %ld, %ld", indexPath.column, indexPath.row, indexPath.item);
}

#pragma mark - <DOPDropDownMenuDelegate>

#pragma mark - <UITableViewDataSource>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString * const categoryListID = @"categoryListID";
    UITableViewCell *categoryListCell = [tableView dequeueReusableCellWithIdentifier:categoryListID];
    
    if (!categoryListCell) {
        
        categoryListCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:categoryListID];
        
    }
    
    return categoryListCell;
}

#pragma mark - <UITableViewDelegate>

#pragma mark - Private Invoke Methods

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
